package jwt.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import jwt.service.JwtService;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RequestMapping
@RestController
public class LoginController {
    static Map<String,String> userInfo = new HashMap<>();
    static {
        userInfo.put("张三","123456");
        userInfo.put("李四","654321");
    }
    @PostMapping("/login")
    public String login(@RequestBody String json){
        JSONObject jsonObject = JSON.parseObject(json);
        String phone = jsonObject.getString("phone");
        String name = jsonObject.getString("name");
        String password = jsonObject.getString("password");
        if(userInfo.containsKey(name) && userInfo.get(name).equals(password)){
            String token = JwtService.getToken(name, phone);
            return token;
        }
        return "token 异常";
    }
}
